%
% Basic nodes like MotorControl aaaaaaand listenIR.
%

\section{Basic nodes}
\subsection{Motor control}

In order to efficiently navigate and explore a maze we needed some sort of abstraction between the motors and the higher-level nodes, so that the nodes responsible for navigating and such don’t need to bother about for instance moving in a straight line and making turns. We wanted the higher level nodes to be able to just send a command to the motors to make the robot go forward a certain distance or turn a certain angle. A node called MotorControl was coded to solve this task. It was from the beginning quite heavily based on the code we wrote for the lab in the beginning of the course.
\\

\subsubsection{How to move ...}
We wanted to be able to go forward and backward x distance units and also be able to turn left and right in 90° degree turns. We had two main challenges, the first to drive forward and backward as straight as possible, that is with as little side-drift as possible, and the second was to turn as close to 90° as possible, so we don’t come out of a corner at a weird or uncomfortable angle.

\subsubsection{... accurately}
In order to fulfill those two goals the MotorControl-node relies exclusively on tick-counts from both wheels. Since we know that the tick count will be zero for both wheels when we start, that means that if we drive in a perfectly straight line, then at the end of that line both wheels should still have the same tick count, whatever it might be. So if a wheel suddenly has more ticks then the other, then the MotorControl-node will slow that wheel down until the tick counts for both wheels are equal again. The same principle is used when it comes to turning 90° left and right, we know (roughly) how many ticks each wheel should make in order to turn 90° left/right, and if either wheel runs ahead it is slowed down in the same manner as described above.
\\

This seemed to work quite well, indeed this is the method which was used in milestone 1 (the wall-following milestone), and although the robot did waggle across the floor when doing straight lines it still managed to stay within a fairly tight corridor and the distances we had to travel before a corner were not too far, so it worked quite nicely.
\\

% Discussion/problems part
Developing the node was somewhat frustrating since we had more than enough trouble with the board. It kept on freezing and sometimes messages sent via topics seemed to be lost altogether or be delayed in their delivery by several seconds which really destroys a tick-count based method (and most other methods as well I would suspect). These troubles were eventually solved by disabling logs and running the serializer-node with a higher priority.

\subsection{IR-sensor transformer}
This node merely listens to the ADC node and passes on values in cm corresponding to the distance from the robot to what the sensor hits. To filter spikes in the signal a continuous mean of the four latest values is used. To convert the signal a double exponential function $A e^{Bx} + C e^{Dx}$ is fit to a number of measured points. For the calibration the mean was done over ten points instead of four. The more points the 